<?php
// +------------------------------------------------------------------
// | cls-captcha [ think captcha, use cache save key-value, does not use session. ]
// | Copyright (c) 2022 All rights reserved.
// | Based on think-captcha, apply to ThinkPHP 6 | 8.
// | Licensed Mulan PSL v2 ( http://license.coscl.org.cn/MulanPSL2 )
// | Author: CLS <422064377>
// | CreateDate: 2024/8/20
// +------------------------------------------------------------------

namespace chleniang\ClsCaptcha;

class CaptchaController
{
    public function index(Captcha $captcha, $config = null)
    {
        try {
            $result = $captcha->create($config);
            return json([
                'code' => 0,
                'data' => $result,
            ]);
        }
        catch (\Exception $e) {
            return json([
                'code' => $e->getCode() > 0 ? $e->getCode() : 995,
                'data' => [],
                'msg'  => $e->getMessage()
            ]);
        }
    }

}